
//  journeyCollectionTableCell.m
//  WhereToTravel
//
//  Created by dlios on 15/10/14.
//  Copyright © 2015年 zhoushengmin. All rights reserved.
//

#import "journeyCollectionTableCell.h"
#import "JourneyModel.h"
#import "JourneyCollectionCell.h"

#define W [[UIScreen mainScreen]bounds].size.width
#define H [[UIScreen mainScreen]bounds].size.height

@implementation journeyCollectionTableCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createView];
    }
    return self;
}

- (void)createView {
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
    flowLayout.itemSize = CGSizeMake(W/3, H/4);
    flowLayout.minimumInteritemSpacing = 0;
    flowLayout.minimumLineSpacing = 0;
    
    self.journeyCollectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, W, H) collectionViewLayout:flowLayout];

    self.journeyCollectionView.backgroundColor = [UIColor clearColor];
    self.journeyCollectionView.scrollEnabled = NO;
    
    self.journeyCollectionView.frame = CGRectZero;
    self.journeyCollectionView.dataSource = self;
    self.journeyCollectionView.delegate = self;
    [self.contentView addSubview:self.journeyCollectionView];
    
    [self.journeyCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top);
        make.left.equalTo(self.mas_left);
        make.right.equalTo(self.mas_right);
        make.width.equalTo(self.mas_width);
        make.height.equalTo(@(H));
    }];
    
    [self.journeyCollectionView registerClass:[JourneyCollectionCell class] forCellWithReuseIdentifier:@"reuse"];

}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.arr.count;
}

-(UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    JourneyCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"reuse" forIndexPath:indexPath];
    cell.backgroundColor = [UIColor clearColor];
    JourneyModel *journeyModel = self.arr[indexPath.row];
    [cell.upImageView sd_setImageWithURL:[NSURL URLWithString:journeyModel.photo] placeholderImage:[UIImage imageNamed:@"占位图"]];
    cell.downLabel.text = journeyModel.cnname;
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    JourneyModel *journeyModel = self.arr[indexPath.row];
    NSString *strId = [NSString stringWithFormat:@"%@",journeyModel.mId];
    NSDictionary *dic = @{@"id":strId,@"photo":journeyModel.photo,@"name":journeyModel.cnname};
    self.block(dic);
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    self.journeyCollectionView.frame = CGRectMake(0, 0, W, H);
}





@end
